package com.atguigu.principle.inversion.improve;

/**
 * @author ccc
 * @create 2020-07-09 15:22
 */
public class DependencyPassOfSetter{
    public static void main(String[] args) {
        ChangHongTV3 changHongTV3 = new ChangHongTV3();

        OpenAndClose3 openAndClose3 = new OpenAndClose3();
        openAndClose3.setItv3(changHongTV3);
        openAndClose3.open();
    }
}

//方式2 通过构造器传递依赖
//开关的接口
interface IOpenAndClose3{
    public void open(); //抽象方法，接收接口
}

interface ITV3 { //ITV 接口 用来搞具体电视类型 长虹之类的
    public void play();
}

//实现接口
class OpenAndClose3 implements IOpenAndClose3{
    private ITV3 tv3;

    public void setItv3(ITV3 tv3){
        this.tv3 = tv3;
    }

    public void open(){
        this.tv3.play();
    }
}

class ChangHongTV3 implements ITV3{ //使用长虹电视来举例
    @Override
    public void play() {
        System.out.println("长虹电视开机");
    }
}